#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
    struct ListNode* list3 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* Headlist3 = list3;
    while (list1 && list2)
    {
        if (list1->val > list2->val)
        {
            list3->next = list2;
            list2 = list2->next;
        }
        else
        {
            list3->next = list1;
            list1 = list1->next;
        }
        list3 = list3->next;
    }
    if (list1 == NULL)
    {
        list3->next = list2;
        return Headlist3->next;
    }
    else if (list2 == NULL)
    {
        list3->next = list1;
        return Headlist3->next;
    }
    else
        return NULL;
}